import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      // redirect: '/module3/index',
      component: HomeView,
    }
  ],
})
// 路由守卫
router.beforeEach((to, from, next) => {
    if(to.query && to.query.token) {
      localStorage.setItem('token', to.query.token)
      next(to.path)
    }
    // 登录验证
    const token = localStorage.getItem('token')
    if (token) {
      next()
    } else {
      next()
      // const redirectUrl = encodeURIComponent(window.location.origin + '/' + to.href);
      // window.location.href = `https://sso.hzcando.com/#/?redirectUrl=${redirectUrl}&appId=233a086111005`;
    }
})

export default router
